package top.lixunda.ecommerce.server.user.api.entity.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.lixunda.common.utils.ObjectValidators;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 商家物流地址
 * </p>
 *
 * @author Xumda
 * @since 2019-12-14
 */
@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("store_address")
public class StoreAddressDO extends Model<StoreAddressDO> {

    private static final long serialVersionUID=1L;

    /**
     * 默认地址标识
     *
     * @see StoreAddressDO#isDefault
     */
    public static final Integer CODE_DEFAULT_ADDRESS = 1;

    /**
     * 非默认地址标识
     *
     * @see StoreAddressDO#isDefault
     */
    public static final Integer CODE_NOT_DEFAULT_ADDRESS = 0;

    /**
     * 可用的地址标识，未删除的地址
     *
     * @see StoreAddressDO#useable
     */
    public static final Integer USEABLE = 1;

    /**
     * 不可用的地址标识，可能已经删除的地址
     *
     * @see StoreAddressDO#useable
     */
    public static final Integer NOT_USEABLE = 0;

    /**
     * 主键Id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 地址名称
     */
    @TableField(value = "name")
    private String name;

    /**
     * 省份Id
     */
    @TableField("province_id")
    private Integer provinceId;

    /**
     * 身份名称
     */
    @TableField("province_name")
    private String provinceName;

    /**
     * 市级Id
     */
    @TableField("city_id")
    private Long cityId;

    /**
     * 市级名称
     */
    @TableField("city_name")
    private String cityName;

    /**
     * 区Id
     */
    @TableField("county_id")
    private Long countyId;

    /**
     * 区名称
     */
    @TableField("county_name")
    private String countyName;

    /**
     * townId
     */
    @TableField("town_id")
    private Long townId;

    /**
     * town名称
     */
    @TableField("town_name")
    private String townName;

    /**
     * villageId
     */
    @TableField("village_id")
    private Long villageId;

    /**
     * village名称
     */
    @TableField("village_name")
    private String villageName;

    /**
     * 详细地址信息
     */
    @TableField("detail")
    private String detail;

    /**
     * 系统账号Id
     */
    @TableField("account")
    private Integer account;

    /**
     * 是否是默认地址，默认地址每个账号有且只能有一个 0 不是默认 1 默认地址
     */
    @TableField("isDefault")
    private Integer isDefault;

    /**
     * 地址创建时间
     */
    @TableField("time")
    private LocalDateTime time;

    /**
     * 地址信息修改时间
     */
    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 备注
     */
    @TableField("remark")
    private String remark;

    /**
     * 是否可用，默认可用，1 可用 0 不可用
     */
    @TableField("useable")
    private Integer useable;

    /**
     * 邮政编码
     */
    @TableField("postal_code")
    private String postalCode;

    /**
     * 联系电话号码
     */
    @TableField("phone")
    private String phone;

    /**
     * 联系人名称
     */
    @TableField("username")
    private String username;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        if (ObjectValidators.isNotEmpty(this.getProvinceName())) {
            builder.append(this.getProvinceName()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getCityName())) {
            builder.append(this.getCityName()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getCountyName())) {
            builder.append(this.getCountyName()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getTownName())) {
            builder.append(this.getTownName()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getVillageName())) {
            builder.append(this.getVillageName()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getDetail())) {
            builder.append(this.getDetail()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getPostalCode())) {
            builder.append(this.getPostalCode()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getUsername())) {
            builder.append(this.getUsername()).append(" ");
        }
        if (ObjectValidators.isNotEmpty(this.getPhone())) {
            builder.append(this.getPhone());
        }
        return builder.toString();
    }
}
